package tungsten.pb;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import tungsten.base.server.BaseClient;
import tungsten.base.server.BaseServer;

/**
 * Created by Lv on 2016/6/17.
 */
public class PBServer extends BaseServer{
    @Override
    protected ChannelInboundHandlerAdapter getChildHandler()
    {
        try {
            PBClient.initialize();
        }
        catch (Exception e)
        {
            System.err.println(e);
        }
        PBAdapter adapter = new PBAdapter();
        PBDecoder decoder = new PBDecoder()
        {
            @Override
            protected BaseClient getNewClient(ChannelHandlerContext ctx)
            {
                return new PBClient(ctx);
            }
        };
        decoder.register(PBAnnotation.class.getPackage());
        adapter.setDecoder(decoder);
        return adapter;
    }
}
